<!-- 事件日志 -->
<template>
  <div class="dashboard-editor-container">
    <el-row style="background: #fff; padding: 16px 16px 0;">
      <connsearch ref="connsearch" :formOptions="formOptions" @search="search" @reset="reset">
      </connsearch>
      <div class="tabclick">
        <div class="tabitem" @click="handleClick()">
          <span><i :class="tab ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i></span>
        </div>
      </div>
      <el-row>
        <el-tabs type="border-card" v-if="tab" style="margin-top:16px;"  @tab-click="tabClick">
          <!-- <el-tab-pane label="按所在分区统计分析" lazy>
            <el-row :gutter="20">
              <el-col :xs="24" :sm="24" :lg="24">
                <piechart  :chartData="pie1Data" @pieclick="echartsClick" title="按所在分区统计分析"/>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="按所在校区统计分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie2Data" @pieclick="echartsClick" title="按所在校区统计分析"/>
            </el-col>
          </el-tab-pane> -->
          <el-tab-pane label="按安全总览分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie3Data" @pieclick="echartsClick" title="按安全总览分析"/>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="按杀软在线分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie4Data" @pieclick="echartsClick" title="按杀软在线分析"/>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="按杀软版本分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie5Data" @pieclick="echartsClick" title="按杀软版本分析"/>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="按病毒库版本分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie6Data" @pieclick="echartsClick" title="按病毒库版本分析"/>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="按零信任在线分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie7Data" @pieclick="echartsClick" title="按零信任在线分析"/>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="按零信任版本分析" lazy>
            <el-col :xs="24" :sm="24" :lg="24">
              <piechart :chartData="pie8Data" @pieclick="echartsClick" title="按零信任版本分析"/>
            </el-col>
          </el-tab-pane>
        </el-tabs>
      </el-row>
      <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :lg="{ span: 24 }" :xl="{ span: 24 }" style="padding-right: 8px;margin:16px 0;">
        <el-table stripe border :data="tableData" style="width: 100%; margin-top: 15px">
          <el-table-column label="序号"  width="60" type="index" :index='(index)=>{return (index + 1) + (this.pageNum - 1)*this.pageSize}'> </el-table-column>
          <!-- <el-table-column label="所在分区" prop="PrimArea" width="120" align="left" show-overflow-tooltip>
              <template slot-scope="{row}">
                <span>{{ row.PrimArea }} / {{ row.SecondArea }}</span>
              </template>
            </el-table-column>
            <el-table-column label="所在校区" show-overflow-tooltip prop="SchoolName" width="140" align="left">
            <template slot-scope="{row}">
              <span>{{ row.SchoolName }}</span>
            </template>
          </el-table-column> -->
          <el-table-column label="资产名称" show-overflow-tooltip prop="DeviceName" width="240" align="left">
            <template slot-scope="{row}">
              <span>{{ row.DeviceName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="在线状态" prop="Status" show-overflow-tooltip width="120" align="left">
            <template slot-scope="{row}">
              <span :style="{color: row.Status === 1 ? '#67C23A' : '#F56C6C'}">{{row.Status === 1 ? '在线' : '离线'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="上报时间" prop="LastReportStatusTime" show-overflow-tooltip width="160" align="left"></el-table-column>
          <el-table-column label="安全总览" prop="SecurityStatus" show-overflow-tooltip align="left">
            <template slot-scope="{row}">
              <span :style="{color: row.SecurityStatus === 0 ? '#F56C6C' : '#67C23A'}">{{row.SecurityStatus === 0 ? '异常' : '正常'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="杀软运行状态" prop="IsKingSoftAVRun" show-overflow-tooltip align="left">
            <template slot-scope="{row}">
              <span :style="{color: row.IsKingSoftAVRun === 0 ? '#F56C6C' : '#67C23A'}">{{row.IsKingSoftAVRun === 0 ? '未运行' : '正在运行'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="杀软版本" prop="KingSoftAVClientVer" show-overflow-tooltip  align="left"></el-table-column>
          <el-table-column label="病毒库版本" prop="KingSoftAVDBVer" show-overflow-tooltip  align="left"></el-table-column>
          <el-table-column label="零信任状态" prop="IsTrustCyberRun" show-overflow-tooltip  align="left">
            <template slot-scope="{row}">
              <span :style="{color: row.IsTrustCyberRun === 0 ? '#F56C6C' : '#67C23A'}">{{row.IsTrustCyberRun === 0 ? '未运行' : '正在运行'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="零信任版本" prop="TrustCyberVer" align="left" show-overflow-tooltip></el-table-column>
        </el-table>
        <el-pagination 
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange" 
          :current-page=pageNum
          :page-size=pageSize
          background 
          layout="total, prev, pager, sizes, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import connsearch from "@/components/connSearch";
import barchart from "./components/barchart.vue";
import piechart from "./components/piechart.vue";
import { parseTime, formatTime2 } from "@/utils/index.js";
import { connrequest } from "@/api/firstPage.js"
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
  directives: { elDragDialog },
  components: { connsearch, barchart, piechart },
  data() {
    let that = this
    return {
      activeName: "",
      tabTitle: '按安全总览分析',
      pageNum: 1,
      pageSize: 10,
      total: 0,
      tab: false,
      logDialog: false,
      logList: [],
      pie1Data: [],
      pie2Data: [],
      pie3Data: [],
      pie4Data: [],
      pie5Data: [],
      pie6Data: [],
      pie7Data: [],
      pie8Data: [],
      tableData:[],
      searchform:{},
      options:{},
      searchobj: {},
      formOptions: [
        // {
        //   col: 8,
        //   label: "分区校区选择",
        //   prop:"SchoolName",
        //   element: "el-cascader",
        //   initValue: "",
        //   placeholder: "请选择校区",
        //   options:[],
        //   props:{emitPath: true, checkStrictly: true, lazy: true, lazyLoad: that.lazyLoad},
        //   events: {
        //     input(val) {
        //       that.searchform.SchoolName = val
        //     },
        //   },
        // },
        {
          col: 4,
          hidden: false,
          label: "在线状态", // label文字
          prop: "Status", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 0, // 字段初始值,
          placeholder: "请选择状态", // elementui组件属性
          labelWidth: '160px',
          options: [
            { label: '全部', value: 0 },
            { label: '在线', value: 1 },
            { label: '离线', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.Status = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "整体安全状态", // label文字
          prop: "SecurityStatusSum", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 0, // 字段初始值,
          placeholder: "请选择状态", // elementui组件属性
          options: [
            { label: '全部', value: 0 },
            { label: '正常', value: 1 },
            { label: '异常', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.SecurityStatusSum = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "杀软状态", // label文字
          prop: "IsKingSoftAVRun", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 0, // 字段初始值,
          placeholder: "请选择状态", // elementui组件属性
          labelWidth: '160px',
          options: [
            { label: '全部', value: 0 },
            { label: '未运行', value: 1 },
            { label: '正在运行', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.IsKingSoftAVRun = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "零信任状态", // label文字
          prop: "IsTrustCyberRun", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 0, // 字段初始值,
          placeholder: "请选择状态", // elementui组件属性
          options: [
            { label: '全部', value: 0 },
            { label: '未运行', value: 1 },
            { label: '正在运行', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.IsTrustCyberRun = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "杀软版本是否等于", // label文字
          prop: "IsEqualAVClientVer", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 1, // 字段初始值,
          placeholder: "请选择是否等于", // elementui组件属性
          labelWidth: '160px',
          clearable: false,
          options: [
            { label: '等于', value: 1 },
            { label: '不等于', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.IsEqualAVClientVer = val
            },
          },
        },
        {
          col: 4,
          label: "杀软版本",
          prop: "KingSoftAVClientVer",
          element: "el-input",
          placeholder: "杀软版本",
          maxlength: 50,
          events: {
            input(val) {
              that.searchform.KingSoftAVClientVer = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "病毒库版本是否等于", // label文字
          prop: "IsEqualAVDBVer", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 1, // 字段初始值,
          placeholder: "请选择是否等于", // elementui组件属性
          labelWidth: '160px',
          clearable: false,
          options: [
            { label: '等于', value: 1 },
            { label: '不等于', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.IsEqualAVDBVer = val
            },
          },
        },
        {
          col: 4,
          label: "病毒库版本",
          prop: "KingSoftAVDBVer",
          element: "el-input",
          placeholder: "病毒库版本",
          maxlength: 50,
          events: {
            input(val) {
              that.searchform.KingSoftAVDBVer = val
            },
          },
        },
        {
          col: 4,
          hidden: false,
          label: "零信任版本是否等于", // label文字
          prop: "IsEqualTrustCyberVer", // 字段名
          element: "el-select", // 指定elementui组件
          initValue: 1, // 字段初始值,
          placeholder: "请选择是否等于", // elementui组件属性
          labelWidth: '160px',
          clearable: false,
          options: [
            { label: '等于', value: 1 },
            { label: '不等于', value: 2 }
          ],
          rules: [], // elementui组件属性
          events: {
            input(val) {
              that.searchform.IsEqualTrustCyberVer = val
            },
          },
        },
        {
          col: 4,
          label: "零信任版本",
          prop: "TrustCyberVer",
          element: "el-input",
          placeholder: "零信任版本",
          maxlength: 50,
          events: {
            input(val) {
              that.searchform.TrustCyberVer = val
            },
          },
        },
      ],
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.pageSize = Cookies.get('DefaultPageLength') * 1
    this.getData()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.GetSchoolStatusSumTree()
  },
  methods: {
    // 获取子节点的校区
    async lazyLoad(node, resolve){
      if(node.level < 3){
        resolve(node.data) 
      }else{
        const data = {
          Paging:{
            QueryPageNo: 1,
            QueryPageLength: 100000
          },
          Filter:{
            SecondArea: node.label,
          }
        }
        const res = await connrequest('GetSchool', data)
        let arr = []
        res.Data.map(item => {
          arr.push( {SubClass: item.SchoolName, value: item.SchoolName, level: 4, children: undefined} )
        })
        resolve(arr) 
      }
    },
    transformData(inputData) {
      const { RootName, PrimArea} = inputData;
        return {
          SubClass: RootName,
          value: RootName,
          level: 1,
          children: PrimArea.map(area => ({
            SubClass: area.PrimAreaName,
            value: area.PrimAreaName,
            level: 2,
            children: area.SecondArea.map(secondArea => ({
              SubClass: secondArea.SecondAreaName,
              value: secondArea.SecondAreaName,
              level: 3,
          }))
        }))
      }
    },
    // 获取校区树
    async GetSchoolStatusSumTree() {
      const res = await connrequest('GetSchoolStatusSumTree')
      this.formOptions.map( item => {
        if(item.label === '分区校区选择'){
          item.options = [this.transformData(res.Data)]
        }
      })
    },
    async changeMailGlobal(row){
      const data = { 
        Filter:{
          DeviceID: row.DeviceID
        }
      }
      const res = await connrequest('GetDeviceHistoryNetworkService', data)
      res.Data = res.Data.map(item => {
        item.TransTime = parseTime(item.TransTime)
        return item
      })
      this.logList = res.Data
      this.logDialog = true
    },
    // 获取所有数据
    getData(){
      this.GetEventLog()
      switch (this.tabTitle) {
        case '按所在分区统计分析':
          this.GetDeviceSecuritySumGroupByArea()
          break;
        case '按所在校区统计分析':
          this.GetDeviceSecuritySumGroupBySchool()
          break;
        case '按安全总览分析':
          this.GetDeviceSecuritySumGroupByStatus()
          break;
        case '按杀软在线分析':
          this.GetDeviceSecuritySumGroupByIsKingSoftAVRun()
          break;
        case '按杀软版本分析':
          this.GetDeviceSecuritySumGroupByKingSoftAVClientVer()
          break;
        case '按病毒库版本分析':
          this.GetDeviceSecuritySumGroupByKingSoftAVDBVer()
          break;
        case '按零信任在线分析':
          this.GetDeviceSecuritySumGroupByIsTrustCyberRun()
          break;
        default:
          this.GetDeviceSecuritySumGroupByTrustCyberVer()
          break;
      }
    },
    echartsClick(val,title){
      this.pageNum = 1
      if(title === '按所在分区统计分析'){
        this.searchobj = { PrimArea: val.split('_')[0], SecondArea: val.split('_')[1] }
        this.GetEventLog(this.searchobj)
      }else if(title === '按所在校区统计分析'){
        this.searchobj = { SchoolName: val }
        this.GetEventLog(this.searchobj)
      }else if(title === '按安全总览分析'){
        this.searchobj = { SecurityStatusSum: val == '正常' ? 1 : 2 }
        this.GetEventLog(this.searchobj)
      }else if(title === '按杀软在线分析'){
        this.searchobj = { IsKingSoftAVRun: val == '未运行' ? 1 : 2 }
        this.GetEventLog(this.searchobj)
      }else if(title === '按杀软版本分析'){
        this.searchobj = { KingSoftAVClientVer: val, IsEqualAVClientVer: 1 }
        this.GetEventLog(this.searchobj)
      }else if(title === '按病毒库版本分析'){
        this.searchobj = { KingSoftAVDBVer: val, IsEqualAVDBVer: 1 }
        this.GetEventLog(this.searchobj)
      }else if(title === '按零信任在线分析'){
        this.searchobj = { IsTrustCyberRun: val == '未运行' ? 1 : 2 }
        this.GetEventLog(this.searchobj)
      }else{
        this.searchobj = { TrustCyberVer: val, IsEqualTrustCyberVer: 1 }
        this.GetEventLog(this.searchobj)
      }
      // this.GetEventLog()
    },
    tabClick(row){
      this.tabTitle = row.label
      switch (row.label) {
        case '按所在分区统计分析':
          this.GetDeviceSecuritySumGroupByArea()
          break;
        case '按所在校区统计分析':
          this.GetDeviceSecuritySumGroupBySchool()
          break;
        case '按安全总览分析':
          this.GetDeviceSecuritySumGroupByStatus()
          break;
        case '按杀软在线分析':
          this.GetDeviceSecuritySumGroupByIsKingSoftAVRun()
          break;
        case '按杀软版本分析':
          this.GetDeviceSecuritySumGroupByKingSoftAVClientVer()
          break;
        case '按病毒库版本分析':
          this.GetDeviceSecuritySumGroupByKingSoftAVDBVer()
          break;
        case '按零信任在线分析':
          this.GetDeviceSecuritySumGroupByIsTrustCyberRun()
          break;
        default:
          this.GetDeviceSecuritySumGroupByTrustCyberVer()
          break;
      }
    },
    // 获取事件日志列表
    async GetEventLog(searchobj = {}){
      const data = {
        Paging: {
          QueryPageNo: this.pageNum,
          QueryPageLength: this.pageSize
        },
        Filter: {
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : undefined,
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : undefined,
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : undefined,
          ...searchobj
        }
      }
      const res = await connrequest('CenterGetDevice', data)
      res.Data = res.Data || []
      res.Data = res.Data.map(item => {
        item.LastReportStatusTime = parseTime(item.LastReportStatusTime)
        return item
      })
      this.tableData = res.Data
      this.total = res.Paging?.TotalCount
    },
    // 按所在分区统计分析
    async GetDeviceSecuritySumGroupByArea(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByArea', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name, value: item.Count})
      })
      this.pie1Data = arr
    },
    // 按所在校区统计分析
    async GetDeviceSecuritySumGroupBySchool(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupBySchool', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name, value: item.Count})
      })
      this.pie2Data = arr
    },
    // 按安全总览分析
    async GetDeviceSecuritySumGroupByStatus(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByStatus', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name, value: item.Count})
      })
      this.pie3Data = arr
    },
    // 按杀软在线分析
    async GetDeviceSecuritySumGroupByIsKingSoftAVRun(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByIsKingSoftAVRun', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.ClassID == '0' ? '未运行' : '正在运行', value: item.Count})
      })
      this.pie4Data = arr
    },
    // 按杀软版本分析
    async GetDeviceSecuritySumGroupByKingSoftAVClientVer(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByKingSoftAVClientVer', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name, value: item.Count})
      })
      this.pie5Data = arr
    },
    // 按病毒库版本分析
    async GetDeviceSecuritySumGroupByKingSoftAVDBVer(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByKingSoftAVDBVer', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name || '', value: item.Count || 0})
      })
      this.pie6Data = arr
    },
    // 按零信任在线分析
    async GetDeviceSecuritySumGroupByIsTrustCyberRun(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByIsTrustCyberRun', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.ClassID == '0' ? '未运行' : '正在运行', value: item.Count})
      })
      this.pie7Data = arr
    },
    // 按零信任版本分析
    async GetDeviceSecuritySumGroupByTrustCyberVer(){
      let arr = []
      const data = {
        Filter:{
          DeviceClass:"Windows",
          PrimArea: this.searchform?.SchoolName?.[1] || '',
          SecondArea: this.searchform?.SchoolName?.[2] || '',
          SchoolName: this.searchform.SchoolName?.[3] || '',
          Status: this.searchform.Status,
          SecurityStatusSum: this.searchform.SecurityStatusSum,
          IsKingSoftAVRun: this.searchform.IsKingSoftAVRun,
          IsTrustCyberRun: this.searchform.IsTrustCyberRun,
          KingSoftAVClientVer: this.searchform.KingSoftAVClientVer,
          KingSoftAVDBVer: this.searchform.KingSoftAVDBVer,
          TrustCyberVer: this.searchform.TrustCyberVer,
          IsEqualAVClientVer: this.searchform.KingSoftAVClientVer ? 1 : '',
          IsEqualAVDBVer: this.searchform.KingSoftAVDBVer ? 1 : '',
          IsEqualTrustCyberVer: this.searchform.TrustCyberVer ? 1 : '',
        }
      }
      const res = await connrequest('GetDeviceSecuritySumGroupByTrustCyberVer', data)
      res.Data = res.Data || []
      res.Data.map( item =>{
        arr.push({name: item.Name, value: item.Count})
      })
      this.pie8Data = arr
    },
    // 搜索
    search(val) {
      this.pageNum = 1
      this.searchobj = {}
      this.searchform = {...val}
      if(this.searchform.timeRange){
        this.searchobj = { StartTime: this.searchform?.timeRange[0] || '', EndTime: this.searchform?.timeRange[1] || '' }
      }
      this.getData()
    },
    // 重置
    reset(){
      let xTime = new Date().getTime()
      let endTime = new Date(new Date().setHours(0, 0, 0, 0))
      let startTime = endTime - (Cookies.get('DefaultLogDays') * 1 * 3600 * 24 * 1000);
      // let arr = [ parseTime(startTime), parseTime(xTime)]
      let arr = [ parseTime(startTime), '']
      this.pageNum = 1
      this.formOptions = this.formOptions.map( item => {
        if(item.label === "在线状态" || item.label === "整体安全状态" || item.label === "杀软状态" || item.label === "零信任状态"){
          item.initValue = 0
        }else if(item.label === "杀软版本是否等于" || item.label === "病毒库版本是否等于" || item.label === "零信任版本是否等于"){
          item.initValue = 1
        }else{
          item.initValue = ""
        }
        return item
      })
      this.searchform = {}
      this.$set(this.searchform,'timeRange', arr)
      this.$set(this.searchform,'Status', 0)
      this.$refs.connsearch.addInitValue()
      this.getData()
    },
    handleSizeChange(pageSize){
      this.pageSize = pageSize
      this.pageNum = 1
      this.GetEventLog({...this.searchobj, StartTime: this.searchobj?.StartTime || this.searchform.timeRange?.[0] ||  '', EndTime: this.searchobj?.EndTime || this.searchform.timeRange?.[1] ||  ''})
    },
    handleCurrentChange( pageNum ){
      this.pageNum = pageNum
      this.GetEventLog({...this.searchobj, StartTime: this.searchobj?.StartTime || this.searchform.timeRange?.[0] ||  '', EndTime: this.searchobj?.EndTime || this.searchform.timeRange?.[1] ||  ''})
    },
    handleClick() {
      this.tab = !this.tab
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./components/css/conncss.scss";
</style>